/***************************************************************
 * Name:      nominasMain.cpp
 * Purpose:   Code for Application Frame
 * Author:     ()
 * Created:   2012-11-23
 * Copyright:  ()
 * License:
 **************************************************************/

#include "nominasMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(nominasFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)
#include "operacionesBD.h"
#include "empleado.h"
//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(nominasFrame)
listaemp *lista;//Creo aqui la lista para poder usarla en todo el programa
const long nominasFrame::ID_STATICBOX1 = wxNewId();
const long nominasFrame::ID_LISTBOX1 = wxNewId();
const long nominasFrame::ID_STATICBOX2 = wxNewId();
const long nominasFrame::ID_STATICTEXT1 = wxNewId();
const long nominasFrame::ID_TEXTCTRL1 = wxNewId();
const long nominasFrame::ID_STATICTEXT6 = wxNewId();
const long nominasFrame::ID_TEXTCTRL2 = wxNewId();
const long nominasFrame::ID_STATICBOX3 = wxNewId();
const long nominasFrame::ID_STATICTEXT2 = wxNewId();
const long nominasFrame::ID_TEXTCTRL3 = wxNewId();
const long nominasFrame::ID_STATICTEXT3 = wxNewId();
const long nominasFrame::ID_TEXTCTRL4 = wxNewId();
const long nominasFrame::ID_STATICTEXT4 = wxNewId();
const long nominasFrame::ID_TEXTCTRL5 = wxNewId();
const long nominasFrame::ID_STATICTEXT5 = wxNewId();
const long nominasFrame::ID_TEXTCTRL6 = wxNewId();
const long nominasFrame::ID_STATICTEXT7 = wxNewId();
const long nominasFrame::ID_TEXTCTRL7 = wxNewId();
const long nominasFrame::ID_STATICTEXT8 = wxNewId();
const long nominasFrame::ID_TEXTCTRL8 = wxNewId();
const long nominasFrame::ID_STATICBOX4 = wxNewId();
const long nominasFrame::ID_STATICTEXT9 = wxNewId();
const long nominasFrame::ID_TEXTCTRL9 = wxNewId();
const long nominasFrame::ID_STATICTEXT10 = wxNewId();
const long nominasFrame::ID_TEXTCTRL10 = wxNewId();
const long nominasFrame::ID_STATICTEXT11 = wxNewId();
const long nominasFrame::ID_TEXTCTRL11 = wxNewId();
const long nominasFrame::ID_BUTTON1 = wxNewId();
const long nominasFrame::ID_BUTTON2 = wxNewId();
const long nominasFrame::ID_BUTTON3 = wxNewId();
const long nominasFrame::ID_BUTTON4 = wxNewId();
const long nominasFrame::ID_BUTTON5 = wxNewId();
const long nominasFrame::ID_BUTTON6 = wxNewId();
const long nominasFrame::ID_BUTTON7 = wxNewId();
const long nominasFrame::ID_PANEL1 = wxNewId();
const long nominasFrame::idMenuQuit = wxNewId();
const long nominasFrame::idMenuAbout = wxNewId();
const long nominasFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(nominasFrame,wxFrame)
    //(*EventTable(nominasFrame)
    //*)
END_EVENT_TABLE()

nominasFrame::nominasFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(nominasFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(799,560));
    Panel = new wxPanel(this, ID_PANEL1, wxPoint(32,48), wxSize(799,504), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    marcoListado = new wxStaticBox(Panel, ID_STATICBOX1, _("Listado de Empleados"), wxPoint(16,16), wxSize(240,480), 0, _T("ID_STATICBOX1"));
    listaEmp = new wxListBox(Panel, ID_LISTBOX1, wxPoint(32,48), wxSize(200,288), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
    marcoDatos = new wxStaticBox(Panel, ID_STATICBOX2, _("Datos de Empleados"), wxPoint(288,16), wxSize(504,480), 0, _T("ID_STATICBOX2"));
    StaticText1 = new wxStaticText(Panel, ID_STATICTEXT1, _("&Nombre:"), wxPoint(320,64), wxSize(48,16), 0, _T("ID_STATICTEXT1"));
    nombreTxt = new wxTextCtrl(Panel, ID_TEXTCTRL1, wxEmptyString, wxPoint(384,56), wxSize(368,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    StaticText6 = new wxStaticText(Panel, ID_STATICTEXT6, _("&Apellido 1:"), wxPoint(320,96), wxSize(56,16), 0, _T("ID_STATICTEXT6"));
    ape1Txt = new wxTextCtrl(Panel, ID_TEXTCTRL2, wxEmptyString, wxPoint(384,88), wxSize(144,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
    marcoPers = new wxStaticBox(Panel, ID_STATICBOX3, _("Personales"), wxPoint(304,32), wxSize(472,192), 0, _T("ID_STATICBOX3"));
    StaticText2 = new wxStaticText(Panel, ID_STATICTEXT2, _("&Direccion:"), wxPoint(320,136), wxSize(48,13), 0, _T("ID_STATICTEXT2"));
    dirTxt = new wxTextCtrl(Panel, ID_TEXTCTRL3, wxEmptyString, wxPoint(384,128), wxSize(368,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
    StaticText3 = new wxStaticText(Panel, ID_STATICTEXT3, _("&Telefono:"), wxPoint(320,168), wxDefaultSize, 0, _T("ID_STATICTEXT3"));
    tlfTxt = new wxTextCtrl(Panel, ID_TEXTCTRL4, wxEmptyString, wxPoint(384,160), wxSize(80,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
    StaticText4 = new wxStaticText(Panel, ID_STATICTEXT4, _("A&pellido 2:"), wxPoint(536,96), wxSize(64,13), 0, _T("ID_STATICTEXT4"));
    ape2Txt = new wxTextCtrl(Panel, ID_TEXTCTRL5, wxEmptyString, wxPoint(600,88), wxSize(152,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
    StaticText5 = new wxStaticText(Panel, ID_STATICTEXT5, _("D.N.I:"), wxPoint(560,160), wxSize(40,13), 0, _T("ID_STATICTEXT5"));
    dniTxt = new wxTextCtrl(Panel, ID_TEXTCTRL6, wxEmptyString, wxPoint(616,160), wxSize(136,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
    StaticText7 = new wxStaticText(Panel, ID_STATICTEXT7, _("Numero S.S:"), wxPoint(320,200), wxDefaultSize, 0, _T("ID_STATICTEXT7"));
    ssTxt = new wxTextCtrl(Panel, ID_TEXTCTRL7, wxEmptyString, wxPoint(384,192), wxSize(104,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL7"));
    StaticText8 = new wxStaticText(Panel, ID_STATICTEXT8, _("Cuenta bancaria:"), wxPoint(512,200), wxDefaultSize, 0, _T("ID_STATICTEXT8"));
    bancoTxt = new wxTextCtrl(Panel, ID_TEXTCTRL8, wxEmptyString, wxPoint(600,192), wxSize(152,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL8"));
    marcoProf = new wxStaticBox(Panel, ID_STATICBOX4, _("Profesionales"), wxPoint(304,232), wxSize(200,144), 0, _T("ID_STATICBOX4"));
    StaticText9 = new wxStaticText(Panel, ID_STATICTEXT9, _("Salario:"), wxPoint(328,264), wxDefaultSize, 0, _T("ID_STATICTEXT9"));
    sueldoTxt = new wxTextCtrl(Panel, ID_TEXTCTRL9, wxEmptyString, wxPoint(376,256), wxSize(96,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL9"));
    StaticText10 = new wxStaticText(Panel, ID_STATICTEXT10, _("Horas extra:"), wxPoint(328,304), wxDefaultSize, 0, _T("ID_STATICTEXT10"));
    TextCtrl10 = new wxTextCtrl(Panel, ID_TEXTCTRL10, wxEmptyString, wxPoint(416,296), wxSize(56,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL10"));
    StaticText11 = new wxStaticText(Panel, ID_STATICTEXT11, _("Antiguedad:"), wxPoint(328,344), wxDefaultSize, 0, _T("ID_STATICTEXT11"));
    viejoTxt = new wxTextCtrl(Panel, ID_TEXTCTRL11, wxEmptyString, wxPoint(416,336), wxSize(56,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL11"));
    Button1 = new wxButton(Panel, ID_BUTTON1, _("NUEVO EMPLEADO"), wxPoint(32,344), wxSize(200,32), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(Panel, ID_BUTTON2, _("BUSCAR EMPLEADO"), wxPoint(32,384), wxSize(200,32), 0, wxDefaultValidator, _T("ID_BUTTON2"));
    Button3 = new wxButton(Panel, ID_BUTTON3, _("ACTUALIZAR"), wxPoint(32,424), wxSize(200,32), 0, wxDefaultValidator, _T("ID_BUTTON3"));
    finBtn = new wxButton(Panel, ID_BUTTON4, _("SALIR"), wxPoint(32,464), wxSize(200,23), 0, wxDefaultValidator, _T("ID_BUTTON4"));
    bdLink = new wxButton(Panel, ID_BUTTON5, _("CONECTAR BASE DE DATOS"), wxPoint(304,392), wxSize(200,24), 0, wxDefaultValidator, _T("ID_BUTTON5"));
    borroBtn = new wxButton(Panel, ID_BUTTON6, _("BORRAR DATOS"), wxPoint(304,424), wxSize(200,23), 0, wxDefaultValidator, _T("ID_BUTTON6"));
    nominaBtn = new wxButton(Panel, ID_BUTTON7, _("GENERAR NOMINA"), wxPoint(304,456), wxSize(200,23), 0, wxDefaultValidator, _T("ID_BUTTON7"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&nominasFrame::OnfinBtnClick);
    Connect(ID_BUTTON5,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&nominasFrame::OnbdLinkClick);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&nominasFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&nominasFrame::OnAbout);
    //*)
}

nominasFrame::~nominasFrame()
{
    //(*Destroy(nominasFrame)
    //*)
}

void nominasFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void nominasFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void nominasFrame::OnfinBtnClick(wxCommandEvent& event)
{
    desconectarBD();
}



void nominasFrame::OnbdLinkClick(wxCommandEvent& event)
{
    cargarBD();
}

